import Vue from 'vue';
import Store from '@/views/task-log/Store';
import { LIST_NAME } from '@/views/task-log/constants';
import { HeaderForm, Table } from '@/views/task-log/components';
import { formatDate } from '@/utils/util';
import { TOP_CHANNELS } from '@/constants';

Vue.component(HeaderForm.name, HeaderForm);
Vue.component(Table.name, Table);

export default {
  metaInfo: {
    title: '调价记录',
  },
  data() {
    return {
      store: new Store([{ listName: LIST_NAME }]),
      topChannelList: TOP_CHANNELS,
    };
  },
  methods: {
    handleCurrentChange() {},
    ...['pageSizeChange', 'pageNumChange', 'queryTaskLog'].reduce(
      (prev, curr) => ({
        ...prev,
        [curr](e) {
          this.store[curr](e);
        },
      }),
      {},
    ),
  },
  computed: {
    ...['formQueryValue', 'list', 'querying'].reduce(
      (prev, curr) => ({
        ...prev,
        [curr]: {
          get() {
            if (curr === 'list') {
              const { data = [], ...restParams } = this.store[curr][LIST_NAME];
              this.store.querying = this.store[curr][LIST_NAME].loading;
              return {
                ...restParams,
                data: data.map(item => ({
                  ...item,
                  topChannelName: TOP_CHANNELS.find(i => i.id === item.topChannelCode)?.name,
                  lastModify: formatDate(new Date(item.lastModify), 'yyyy-MM-dd hh:mm:ss'),
                  createTime: formatDate(new Date(item.createTime), 'yyyy-MM-dd hh:mm:ss'),
                })),
              };
            }
            return this.store[curr];
          },
        },
      }),
      {},
    ),
  },
  async created() {},
  async mounted() {},
};
